﻿using BrightIdeasSoftware;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BO;
using System.Collections;
using UI.Core;
using System.Data.SqlClient;
using System.Data.Entity;
namespace UI
{
    public partial class DateTargetReport : ReportFormBase,IMenuForm
    {
        public DateTargetReport()
        {
            InitializeComponent();
        }

        protected override void InitGrid()
        {
            
            MyGrid.Columns.AddRange(new OLVColumn[] { 
                new OLVColumn("开始日期","BeginDate"){ Width=110, AspectToStringFormat="{0:d}"},
                new OLVColumn("结束日期","EndDate"){ Width=110,AspectToStringFormat="{0:d}"},
                new OLVColumn(FieldHelper.cnName.Company, "CompanyName"),
                new OLVColumn(FieldHelper.cnName.Center, "CenterName"),
                new OLVColumn(FieldHelper.cnName.Department, "DepartmentName"),
                 new OLVColumn(FieldHelper.cnName.Principal, "Principal"),
                new OLVColumn("已达成", "ReachedAmount"),
                new OLVColumn("业绩目标", "Amount"),
                new OLVColumn("达成率(%)", "Rate"),
            
            });

           
        }
        IEnumerable mySource;

        protected override IEnumerable MySource
        {
            get
            {
                return mySource;
            }
        }
        protected override void FetchData()
        {

            var data = ListFactory<DateTargetsList>.GetList("");
            var billings = ListFactory<BillingList>.GetList(" Billing.HasDeleted=0 and Billing.IsConfirm=1 ");
            var companys =ListFactory<CompanyList>.GetList("");
            var centers = ListFactory<CenterList>.GetList("");
            var departments = ListFactory<DepartmentList>.GetList("");
            foreach (var item in data)
            {
                item.LoadReachedAmount(billings,companys,centers,departments);
            }
            mySource = data;
        }
    }
}
